package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.CheckItemDao;
import com.itheima.entity.PageResult;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author chencfgs
 * @date 2019-11-29 9:51
 */
@Service(interfaceClass = CheckItemService.class)
@Transactional
public class CheckItemServiceImpl implements CheckItemService {

    @Autowired
    private CheckItemDao checkItemDao;

    @Override
    public void add(CheckItem checkItem) {
        checkItemDao.add(checkItem);
    }

    @Override
    public PageResult pageQuery(Integer currentPage, Integer pageSize, String queryString) {
        PageHelper.startPage(currentPage, pageSize);
        Page<CheckItem> page = checkItemDao.selectByCondition(queryString);

        return new PageResult(page.getTotal(), page.getResult());
    }

    @Override
    public Integer delectById(Integer id) {
        Integer count = checkItemDao.delectById(id);
        return count;
    }

    @Override
    public Long findById(Integer id) {
        Long aLong = checkItemDao.searchById(id);
        return aLong;
    }

    @Override
    public void updata(CheckItem checkItem) {
        checkItemDao.updata(checkItem);
    }

    /**
     * axios查询所有item到datalist
     *
     * @return
     */
    @Override
    public List<CheckItem> findAll() {
        return checkItemDao.findAll();
    }

    @Override
    public void delectByIdT(Integer id) {
        checkItemDao.delectByIdT(id);
    }

    @Override
    public void delete(Integer id) {
        checkItemDao.delete(id);
    }


//    @Override
//    public Result delectById(Integer integers) {
//        Long aLong = checkItemDao.findById();
//
//        if (aLong > 0) {
//            Integer num = checkItemDao.delectById();
//            if (num > 0) {
//                return new Result(true, MessageConstant.DELETE_CHECKGROUP_SUCCESS);
//            }
//        }
//        return new Result(false, MessageConstant.DELETE_CHECKGROUP_FAIL)
//    }
}
